<?php
class psite extends spModel
{	
	var $pk = "siteid";
	var $table = "psite";

		var $verifier = array(
		"rules" => array(
			'domain' => array(
				'notnull' => TRUE,
				'minlength' => 2,
				'maxlength' => 20,
			),
			'title' => array(
				'notnull' => TRUE,
				'minlength' => 2,
				'maxlength' => 12, 
			),
		),
		"messages" => array( // 提示信息
			'domain' => array(
				'notnull' => "网站域名不能为空",
				'minlength' => "网站域名不能少于3个字符",
				'maxlength' => "网站域名不能大于20个字符"
			),
				
			'title' => array(
				'notnull' => "网站名称不能为空",
				'minlength' => "网站名称不能少于3个字符",
				'maxlength' => "网站名称不能大于20个字符"
			),
		)
	);
	
	var $linker = array(
		array(
			'type' => 'hasone',   // 一对一关联
			'map' => 'site',    // 关联的标识
			'mapkey' => 'siteid',  // 本表与对应表关联的字段名		
			'fclass' => 'record',   // 对应表的类名		
			'fkey' => 'siteid',    // 对应表中关联的字段名		
			'enabled' => false      // 是否启用关联		
		),
		array(
			'type' => 'hasmany',   // 一对多关联
			'map' => 'record',    // 关联的标识
			'mapkey' => 'siteid', 
			'fclass' => 'site',
			'fkey' => 'siteid',
			'enabled' => true
		),
	);
	/**
	 * 	添加网站
	 * Enter description here ...
	 * @param unknown_type $data
	 */
	function insert($data)
	{
		$data['userid']=$_SESSION["userinfo"]["userid"];
		$data['addtime']=strtotime(date("Y-m-d H:i:s"));
		$data['lasttime']=strtotime(date("Y-m-d H:i:s"));
        if($this->create($data)){
			return true;			
		} 
		else{
			return false;
		}
	}

	/**
	 * 	获取当期用户网站
	 * Enter description here ...
	 * @param unknown_type $page
	 * @param unknown_type $pageSize
	 * @param unknown_type $con
	 */
	function a_site($page = 1, $pageSize = 10, $con)
	{
		if(isset($con)){
			$conditions= array(
				"userid" => $_SESSION["userinfo"]["userid"],
				"groupid"=>$con
		);
		}else {
			$conditions= array(
				"userid" => $_SESSION["userinfo"]["userid"],);
		}
		$result['list'] = $this->spPager($page, $pageSize)->findAll($conditions);
		$result['pagedata'] = $this->spPager()->getPager();
		return $result;
	}
	
}